<?php
/**
 * 订单列表
 * Created by PhpStorm.
 * User: zhaofengjun
 * Date: 2019/3/28
 * Time: 15:18
 */

namespace app\common\model;

use traits\model\SoftDelete;


class Orders extends Model
{
    use SoftDelete;
    protected $name = 'orders';
    protected $autoWriteTimestamp = true;
    //protected $autoReadRelations = true;

    /**
     * 获取订单所属的商品
     */
    public function orderDetails()
    {
        return $this->hasMany('OrderDetails','order_id','id')->field('id,order_id,goods_id,goods_num,price,subtotal,remark');
    }


    /**
     * 获取订单用户信息
     */
    public function gUser()
    {
        return $this->belongsTo('Users','user_id','id')->field('id,name,mobile,address');
    }








    protected function getStatusTextAttr($vaule, $data)
    {
        $text = [
            0 => '未支付',
            1 => '已支付'
        ];
        return $text[$data['status']];
    }

    protected function getLastLoginTimeAttr($value)
    {
        return $value>0?date('Y-m-d H:i:s',$value):'/';
    }


    protected function getRegTimeAttr($value)
    {
        return $value>0?date('Y-m-d H:i:s',$value):'/';
    }


}